<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta name="decorator" content="sysDefault" content="text/html; charset=utf-8" />
<script src="${staticPath}/js/pospay/opendialog.js" type="text/javascript"></script>

<script type="text/javascript">
	//模块信息
	var sysModule = "";
	$(document).ready(function() {
			$("#key").focus();
			$("#dataForm").validate({
				submitHandler: function(form){
					var key = $.trim(form.key.value);
					$.get("${contextPath}/sys/base/module/validate?key="+key+"&id="+form.id.value,function(result){
						if(result == 0){
								//模块信息拼装json
								sysModule += "{'id':'"+form.id.value+"',";
								sysModule += "'name':'"+form.name.value+"',";
								sysModule += "'key':'"+key+"',";
								sysModule += "'orderBy':'"+form.orderBy.value+"',";
								sysModule += "'remark':'"+form.remark.value+"'}";
								
								var param = {"sysBaseModule":sysModule};
								$.post(form.action,param,function(data){
									Oosp_Loading('正在提交，请稍等...');
									window.open('${contextPath}'+data,"_self");
								});
						}else{
							alert("对不起,key已经存在,请重新填写!");
							$("#key").focus();
						}
					});
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
		});
	});
</script>
</head>
<body>
	<div class="container-fluid">
		<div class="row">
			<div class="col-xs-12">
				<form:form id="dataForm" modelAttribute="sysBaseModule"
					action="${contextPath}/sys/base/module/save" method="post"
					class="form-horizontal" role="form">
					
					<div class="panel panel-default">
						<div class="panel-heading">
							<h3 class="panel-title">
								新增数据 <a class="btn btn-default btn-sm pull-right" role="button"
									href="${contextPath}/sys/base/module/list" >返回</a>
							</h3>
						</div>
						<div class="panel-body">
							<form:hidden path="id" />
							<tags:message content="${message}" />
							<div class="form-group">
								<label for="saleNo" class="col-sm-2 control-label">名称:</label>
								<div class="col-sm-2">
									<form:input id="name" path="name" maxlength="20"
										class="form-control required" />
								</div>
							</div>
							<div class="form-group">
								<label for="salenoOffline" class="col-sm-2 control-label">key:</label>
								<div class="col-sm-2">
									<form:input id="key" path="key" maxlength="20"
										class="form-control required" />
								</div>
							</div>
							<div class="form-group">
								<label for="salenoOffline" class="col-sm-2 control-label">排序:</label>
								<div class="col-sm-2">
									<form:input id="orderBy" path="orderBy" maxlength="20"
										class="form-control required" />
								</div>
							</div>
							<div class="form-group">
								<label for="saleChannel" class="col-sm-2 control-label">备注:</label>
								<div class="col-sm-2">
									<form:input id="remark" path="remark" maxlength="20"
										class="form-control" />
								</div>
							</div>
						</div>
						
						<div class="form-group">
							<div class="col-sm-offset-2 col-sm-10">
								<input class="btn btn-primary" type="submit" value="保 存" /> 
								<a class="btn btn-default" href="${contextPath}/sys/base/module/list" >返 回</a>
							</div>
						</div>
					</div>
					
				</form:form>
			</div>
		</div>
	</div>
</body>
</html>